﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TotalApplication.viewmodels
{
    public partial class MainWindowViewModel : ObservableValidator
    {
        [ObservableProperty]
        private string _title;

        [ObservableProperty]
        private ObservableCollection<string> _items = new ObservableCollection<string> { "Item 1", "Item 2", "Item 3" };

        [ObservableProperty]
        [NotifyDataErrorInfo]
        [Required(ErrorMessage = "数值不能为空")]
        [Range(0.01, 10000, ErrorMessage = "范围: 0.01 ~ 10,000")]
        private double _luckyNumber;

        private static readonly MainWindowViewModel _viewModel = new MainWindowViewModel();

        public static MainWindowViewModel GetInstance()
        {
            return _viewModel;
        }

        public MainWindowViewModel()
        {
            Title = string.Empty;
        }

        [RelayCommand]
        public void Click()
        {
            _viewModel.Title = "changed success";
            _viewModel.LuckyNumber = new Random().NextDouble() * 10000;

        }
    }
}
